package org.liu.simpleTank;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import java.util.EventListener;
import java.util.EventObject;

public class ControlStatus {
	// properties
	private int dir;
	private boolean fire;
	{
		dir = CONSTS.NODIR;
		fire = false;
	}
	
	public void setDir(int dir) {
		int old = this.dir;
		this.dir = dir;
		if(old != dir) {
			changed();
		}
	}
	
	public int getDir() {
		return this.dir;
	}
	
	public void setFire(boolean fire) {
		boolean old = this.fire;
		this.fire = fire;
		if(old != fire) {
			changed();
		}
	}
	
	public boolean getFire() {
		return this.fire;
	}
	
	private void changed() {
		ListIterator<ControlStatusChangedListener> iter = listeners.listIterator();
		while(iter.hasNext()) {
			iter.next().changed(new EventObject(this));
		}
	}
	
	// listener related
	private ArrayList<ControlStatusChangedListener> listeners;
	{
		listeners = new ArrayList<ControlStatusChangedListener>(10);
	}
	public void addListener(ControlStatusChangedListener listener) {
		listeners.add(listener);
	}
	
	public void removeListener(ControlStatusChangedListener listener) {
		listeners.remove(listener);
	}
	
	public static abstract class ControlStatusChangedListener implements java.util.EventListener {
		public abstract void changed(EventObject e);
	}
}